/*
 * File:   main.cpp
 * Authors: bnoleau, cbourdieu, rlecrois
 *
 * Created on 18 octobre 2011, 10:58
 */

#include <cstdlib>
#include <time.h>
#include <iostream>
#include <fstream>
#include <list>

#include "source/Graph.h"
#include "source/builder/MinisatBuilder.h"
#include "source/factory/Factory.h"
#include "source/strategy/Glouton.h"
#include "source/strategy/MinisatCover.h"
#include "source/strategy/OptimalSmallCover.h"
#include "source/strategy/OptimalTree.h"
#include "source/strategy/TwoApprDfs.h"
#include "source/strategy/TwoApprKillNeighbor.h"
#include "test/FactoryTest.h"


using namespace std;

Graph* createGraph() {
	Factory* f  = Factory::getInstance();
	Graph* g = f->createGraph(10, 0);
	g->createEdge(g->nodeAt(0), g->nodeAt(4));
	g->createEdge(g->nodeAt(1), g->nodeAt(4));
	g->createEdge(g->nodeAt(2), g->nodeAt(4));
	g->createEdge(g->nodeAt(3), g->nodeAt(4));
	g->createEdge(g->nodeAt(5), g->nodeAt(3));
	g->createEdge(g->nodeAt(5), g->nodeAt(4));
	g->createEdge(g->nodeAt(5), g->nodeAt(6));
	g->createEdge(g->nodeAt(5), g->nodeAt(7));
	g->createEdge(g->nodeAt(5), g->nodeAt(8));
	g->createEdge(g->nodeAt(5), g->nodeAt(9));
	return g;	
}

void printCover(list<int> cover) {
	for (list<int>::iterator it = cover.begin(); it != cover.end(); ++it)
		cout << *it << " -  " ;
	cout << endl;
}

int main(int argc, char** argv) {
	srand(time(NULL));
	
	list<int> cover;
	Graph* g = createGraph();

	cout << "***Graphe de test : " << endl << *g << endl;
	g->setStrategy(new Glouton());
	cout << "Glouton : " << endl;
	cover = g->launchVertexCover();
	printCover(cover);

	g = createGraph();
	g->setStrategy(new OptimalSmallCover(2));
	cout << "OptimalSmallCover : " << endl;
	cover = g->launchVertexCover();
	printCover(cover);

	g = createGraph();
	g->setStrategy(new TwoApprDfs());
	cout << "TwoApprDfs : " << endl;
	cover = g->launchVertexCover();
	printCover(cover);

	g = createGraph();
	g->setStrategy(new TwoApprKillNeighbor());
	cout << "TwoApprKillNeighbor : " << endl;
	cover = g->launchVertexCover();
	printCover(cover);

	g = createGraph();
	g->setStrategy(new MinisatCover());
	cout << "MinisatCover : " << endl;
	cover = g->launchVertexCover();
	printCover(cover);

	g = Factory::getInstance()->createBinaryTree(10);
	cout << endl << "***Arbre de test : " << endl <<  *g << endl;
	g->setStrategy(new OptimalTree());
	cout << "OptimalTree : " << endl;
	cover = g->launchVertexCover();
	printCover(cover);

	return 0;
}
